<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="车辆ID" prop="bicycleId">
        <el-input v-model="queryParams.bicycleId" placeholder="请输入车辆ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="车辆状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择车辆状态" clearable>
          <el-option v-for="dict in dict.type.status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="客户名称" prop="clientName">
        <el-input v-model="queryParams.clientName" placeholder="请输入客户名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="销售订单号" prop="clientOrderNumber">
        <el-input v-model="queryParams.clientOrderNumber" placeholder="请输入销售订单号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="规格型号" prop="specifications">
        <el-input v-model="queryParams.specifications" placeholder="请输入规格型号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="客户型号" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入客户型号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="颜色" prop="color">
        <el-select v-model="queryParams.color" filterable placeholder="请选择颜色" clearable>
          <el-option v-for="dict in dict.type.colour" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="入库日期段" prop="WarehousingDate">
        <el-input v-model="queryParams.WarehousingDate" placeholder="请选择入库日期段" clearable type="date"
          value-format="yyyy-MM-dd" />
      </el-form-item>
      <el-form-item label="出库日期段" prop="OutboundDate">
        <el-input v-model="queryParams.OutboundDate" placeholder="请选择出库日期段" clearable type="date"
          value-format="yyyy-MM-dd" />
      </el-form-item>
      <el-form-item label="客户下单日期段" prop="clinentOrderDate">
        <el-input v-model="queryParams.clinentOrderDate" placeholder="请选择客户下单日期段" clearable type="date"
          value-format="yyyy-MM-dd" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table :data="packageList">
      <el-table-column label="车辆ID" align="center" prop="bicycleId" />
      <el-table-column label="销售订单" align="center" prop="clientOrderNumber" />
      <el-table-column label="客户下单日期" align="center" prop="clinentOrderDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.clinentOrderDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产工单号" align="center" prop="orderId" />
      <el-table-column label="入库类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.incoming_type" :value="scope.row.type" />
        </template>
      </el-table-column>
      <el-table-column label="入库单号" align="center" prop="warehouseEntryNumber" />
      <el-table-column label="客户名称" align="center" prop="clientName" />
      <el-table-column label="产品编码" align="center" prop="productId" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="规格型号" align="center" prop="specifications" />
      <el-table-column label="颜色" align="center" prop="color">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.colour" :value="scope.row.color" />
        </template>
      </el-table-column>
      <el-table-column label="毛重" align="center" prop="grossWeight" />
      <el-table-column label="净重" align="center" prop="net" />
      <el-table-column label="包装日期" align="center" prop="packagingDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.packagingDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="入库日期" align="center" prop="WarehousingDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.WarehousingDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出库日期" align="center" prop="OutboundDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.OutboundDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="控制器号" align="center" prop="controllerId" />
      <el-table-column v-for="(item, index) in fittings" :key="index" :label="item.fittingName" align="center"
        :prop="item.fittingFabienName" v-if="item.delFlag" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="状态" align="center" prop="status">
        <template #default="{ row }">
          <el-tag v-if="row.status == 1" type="success">排单</el-tag>
          <el-tag v-if="row.status == 2" type="success">采集</el-tag>
          <el-tag v-if="row.status == 3" type="success">包装</el-tag>
          <el-tag v-if="row.status == 4" type="success">入库</el-tag>
          <el-tag v-if="row.status == 5" type="success">出库</el-tag>
        </template>
      </el-table-column>
      <el-table-column fixed="right" width="100" align="center">
        <template slot="header">
          <i class="el-icon-setting" style="font-size: 22px; cursor: pointer" @click="showColumnOption"></i>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <transition name="fade">
      <div class="columnOption" v-show="isShowColumn">
        <div class="content">
          <div class="head">选择显示字段</div>
          <div class="body">
            <el-checkbox v-for="(item, index) in fittings" :key="index" v-model="item.delFlag">{{ item.fittingName
            }}</el-checkbox>
          </div>
          <div class="footer">
            <el-button size="small" type="primary" plain @click="saveColumn">保存列配置</el-button>
          </div>
        </div>
      </div>
    </transition>
  </div>
</template>

<script>
import { listBicycle } from "@/api/storage/packageWeighing/package";
import { selectFittings } from "@/api/storage/controller/bicycle";
export default {
  name: "Package",
  dicts: ['colour', "status", "incoming_type"],
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 包装称重表格数据
      packageList: [],
      //筛选显示
      isShowColumn: false,
      fittings: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    selectFittings().then(res => {
      this.fittings = res.data
      this.fittings.forEach(item => {
        if (item.delFlag == 0) {
          item.delFlag = true
        } else {
          item.delFlag = false
        }
      })
    })
  },
  mounted() {
    this.getList();
  },
  methods: {
    showColumnOption() {
      this.isShowColumn = true;
    },
    saveColumn() {
      this.isShowColumn = false;
    },
    /** 查询包装称重列表 */
    getList() {
      listBicycle(this.queryParams).then(response => {
        this.packageList = response.rows;
        this.packageList.forEach(item => {
          this.fittings.forEach(it => {
            const fittingKeyName = it.fittingFabienName;
            if (item.map && item.map[fittingKeyName] && item.map[fittingKeyName] !== "") {
              item[fittingKeyName] = item.map[fittingKeyName]
            }
          })
        })
        this.total = response.total;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        bicycleId: null,
        controllerId: null,
        frameId: null,
        motorId: null,
        batteryId: null,
        meterId: null,
        packagingDate: null,
        grossWeight: null,
        net: null,
        orderId: null,
        audit: null,
        controllerFlag: null,
        cartonNumbers: null,
        orderFlag: null,
        packagingFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
}
</script>
<style scoped>
.columnOption {
  position: fixed;
  z-index: 20;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: row-reverse;
}

.columnOption .content {
  width: 100px;
  height: 100%;
  background-color: rgb(203, 223, 198);
}

.columnOption .content .head {
  width: 100%;
  height: 44px;
  border-bottom: 1px solid #000;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 12px;
}

.columnOption .content .body {
  width: 100%;
  height: calc(100% - 88px);
  box-sizing: border-box;
  padding-top: 10px;
  overflow-y: auto;
}

.columnOption .content .body .items {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.columnOption .content .body .items .el-checkbox {
  width: 100%;
  height: 28px;
  line-height: 28px;
  margin-bottom: 14px;
  display: inline-block;
  font-family: PingFang SC;
  font-style: normal;
  font-weight: normal;
  font-size: 14px;
  color: #000;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-sizing: border-box;
  padding-left: 14px;
}

.columnOption .content .body .items .el-checkbox:hover {
  background-color: #f5f7fa;
}

.columnOption .content .footer {
  width: 100%;
  height: 44px;
  border-top: 1px solid #000;
  display: flex;
  justify-content: center;
  align-items: center;
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s;
}

.fade-enter,
.fade-leave-to {
  opacity: 0;
}
</style>